<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约列表</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-date-picker
                        v-model="pagination.queryDate"
                        type="daterange"
                        value-format="yyyy-MM-dd"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                </el-date-picker>

                <el-input placeholder="会员姓名" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="handleCurrentChange(1)" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="clearCondition()">清除</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="membername" label="会员名称" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="电话号码" align="center"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center" :formatter="dateFormat"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center">
                    <template slot-scope="scope">
                        <el-switch
                                style="display: block"
                                v-model="scope.row.orderStatus"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                :inactive-text="showName(scope.row.orderStatus)"
                                @change="statusEdit(scope.row)"
                        >
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column prop="setmealname" label="套餐名称" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <!--<el-button type="danger" size="mini" @click="handleCreate(scope.row)">干预</el-button>-->
                        <el-button size="mini" type="primary" @click="handleUpdate(scope.row)">医师建议</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="医生建议" :visible.sync="adviseVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本建议" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="写个建议吧">
                                                <el-input v-model="formData.doctorAdvice" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="推荐膳食" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>名称</th>
                                            <th>介绍</th>
                                            <th>食用尺寸</th>
                                            <th>适用年龄</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in foodData">
                                            <td>
                                                <input :id="c.id" v-model="foodIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                            <td><label :for="c.id">{{c.size}}</label></td>
                                            <td><label :for="c.id">{{c.age}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane label="推荐运动" name="thirdly">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>助记码</th>
                                            <th>运动</th>
                                            <th>运动次数</th>
                                            <th>运动时间</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in sportData">
                                            <td>
                                                <input :id="c.id" v-model="sportIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.size}}</label></td>
                                            <td><label :for="c.id">{{c.runtime}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="adviseVisible = false">取消</el-button>
                        <el-button type="primary" @click="advise()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            value: false,//未到诊/已到诊
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 0,
                queryString: null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            foodData: [],//干预和更新表单中对应的膳食列表数据
            sportData: [],//干预和更新表单中对应的运动列表数据
            foodIds: [],//干预表单中食物对应的复选框，基于双向绑定可以进行回显和数据提交
            sportIds: [],//干预表单中运动对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            adviseVisible: false//控制干预窗口显示/隐藏
        },
        created() {
            this.findPage();
        },
        methods: {
            //switch开关编辑预约状态
            statusEdit(row) {
                //把当前状态拿到
                var orderStatusStr = row.orderStatus ? "已到诊" : "未到诊";
                axios.post("/orderlist/statusEdit.do", {
                    //将预约状态和预约id作为参数
                    orderStatus: orderStatusStr,
                    id: row.id
                }).then(res => {
                    if (res.data.flag) {
                        //编辑预约状态成功提示
                        this.$message.success(res.data.message);
                        //查询页面
                        // this.findPage()
                    }
                })
            },

            showName(orderStatus) {
                //把未到诊和已到诊和true false 对应起来
                return orderStatus ? "已到诊" : "未到诊";
            },

            // 弹出干预窗口
            handleUpdate(row) {
                if (!row.orderStatus) {
                    this.$message.error("未到诊用户无法给与建议!");
                    return;
                }
                this.resetForm();
                this.formData.orderId = row.id;
                //弹出干预窗口
                this.adviseVisible = true;
                this.activeName = 'first';
                //发送ajax请求，根据预约订单ID查询当前对应干预，用于基本信息的回显
                /*axios.get("/orderlist/findById.do?orderId=" + row.id).then((res) => {
                    if (res.data.flag) {
                        //查询到数据
                        this.formData = res.data.data;
                    } else {
                        //查询数据失败
                        this.$message.error(res.data.message);
                    }
                });*/
                //发送ajax请求，查询所有的膳食数据，用于展示膳食列表
                axios.get("/food/findAll.do").then((res) => {
                    if (res.data.flag) {
                        //查询检查项数据成功
                        this.foodData = res.data.data;

                    } else {
                        //查询检查项数据失败
                        this.$message.error(res.data.message);
                    }
                });
                //发送ajax请求，查询所有的运动数据，用于展示运动列表
                axios.get("/sport/findAll.do").then((res) => {
                    if (res.data.flag) {
                        //查询检查项数据成功
                        this.sportData = res.data.data;
                    } else {
                        //查询检查项数据失败
                        this.$message.error(res.data.message);
                    }
                });
            },
            //编辑
            advise() {
                //发送ajax请求，将表单数据提交给后台处理
                axios.post("/orderlist/edit.do?foodIds=" + this.foodIds + "&sportIds=" + this.sportIds, this.formData).then((res) => {
                    //关闭编辑窗口
                    this.adviseVisible = false;
                    if (res.data.flag) {
                        //操作成功
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    this.findPage();
                });
            },
            //分页查询
            findPage() {
                //封装分页参数
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString,
                    queryDate:this.pagination.queryDate,
                };
                //发送ajax请求，提交分页相关参数
                axios.post("/orderlist/findPage.do", param).then((res) => {
                    //为VUE对象的模型数据赋值，基于双向数据绑定展示到页面
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                    //对dataList中的预约状态对应转化为true false
                    for (var i = 0; i < this.dataList.length; i++) {
                        if (this.dataList[i].orderStatus === "已到诊") {
                            this.dataList[i].orderStatus = true;
                        } else {
                            this.dataList[i].orderStatus = false;
                        }
                    }
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.foodIds = [];
                this.sportIds = [];
            },

            //切换页码
            handleCurrentChange(currentPage) {
                //为模型数据赋值（当前页面）
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //时间格式化
            dateFormat(row, column) {
                // 获取单元格数据
                let data = row[column.property];
                if (data == null) {
                    return null;
                }
                let dt = new Date(data);
                return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate();
            },
        }
    })
</script>
</html>
